package com.ruoyi.common.utils;

import com.ruoyi.common.core.exception.CustomException;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.Collection;


/**
 * @Auther: tswsoft
 * @Date: 2021/05/21/10:11 AM
 * @Description:
 */
public class AssertUtils {

    public static void notNull(@Nullable Object object, String message) {
        if (object == null) {
            throw new CustomException(message);
        }
    }

    public static void notNull(@Nullable String str, String message) {
        if (StringUtils.isEmpty(str)) {
            throw new CustomException(message);
        }
    }

    public static void notNull(@Nullable Collection<?> collection, String message) {
        if (CollectionUtils.isEmpty(collection)) {
            throw new CustomException(message);
        }
    }

    public static void notNullOrZero(@Nullable Integer value, String message) {
        if (value == null || BigDecimal.valueOf(value).compareTo(BigDecimal.ZERO) == 0) {
            throw new CustomException(message);
        }
    }

    public static void notNullOrZero(@Nullable Long value, String message) {
        if (value == null || BigDecimal.valueOf(value).compareTo(BigDecimal.ZERO) == 0) {
            throw new CustomException(message);
        }
    }

    public static void notNullOrZero(@Nullable BigDecimal value, String message) {
        if (value == null || value.compareTo(BigDecimal.ZERO) == 0) {
            throw new CustomException(message);
        }
    }

    public static void isTrue(boolean expression, String message) {
        if (!expression) {
            throw new CustomException(message);
        }
    }

    public static void trueError(boolean expression, String message) {
        if (expression) {
            throw new CustomException(message);
        }
    }
}
